<%-- 
    Document   : administracaoPerfilCadastrar
    Created on : 22/10/2010, 08:05:46
    Author     : Thiago
--%>

<%@page import="dao.PerfilDAO"%>
<%@page import="dao.UsuarioDAO"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="crypt.Crypt"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="bo.*"%>
<%@page import="beans.*"%>
<%@page import="autenticacao.Sessao"%>
<%
            String moduleId = "24";
            Crypt crypt = new Crypt();
            try {
                crypt.setKey(crypt.Decifragem((String) session.getAttribute("userPhrase")));
                String desafio = crypt.Cifragem(moduleId + "@" + ferramentas.DataHora.formatarDataHora(ferramentas.DataHora.retornarDataHoraAtual(), ferramentas.DataHora.DATE_TIME_FORMAT));
                if (!(new Sessao(session).validarSessao(desafio))) {
                    response.sendRedirect("/" + request.getContextPath());
                }
            } catch (Exception e) {
                response.sendRedirect("/" + request.getContextPath());
            }
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Gestor Operacional</title>
        <link href="<%out.print(new String(request.getRequestURL()).split("pages")[0]);%>css/style.css" type="text/css" rel="stylesheet"/>
        <link href="<%out.print(new String(request.getRequestURL()).split("pages")[0]);%>css/table.css" type="text/css" rel="stylesheet"/>
        <link href="<%out.print(new String(request.getRequestURL()).split("pages")[0]);%>css/anytime.css" rel="stylesheet" type="text/css"/>
        <script type="text/javascript" src="<%out.print(new String(request.getRequestURL()).split("pages")[0]);%>scripts/jquery.js"></script>
        <script type="text/javascript" src="<%out.print(new String(request.getRequestURL()).split("pages")[0]);%>scripts/anytime.js"></script>
        <script type="text/javascript" src="<%out.print(new String(request.getRequestURL()).split("pages")[0]);%>scripts/anytimetz.js"></script>
        <script type="text/javascript" src="<%out.print(new String(request.getRequestURL()).split("pages")[0]);%>scripts/table.js"></script>
    </head>
    <body>
        <table width="100%">
            <tr>
                <td>
                    <jsp:include page = "../menu.jsp" flush = "true"/>
                </td>
            </tr>

            <tr align="center">
                <td><br/><br/>
                    <form name="form1" name="form1" method="post" action="administracaoPerfilCadastrar.jsp">
                        <input type="hidden" name="action" value="executar"/>
                        <%
                                    String action = (String) request.getParameter("action");
                                    Perfil pfl = null;
                                    if ((action != null) && (action.equalsIgnoreCase("executar"))) {
                                        try {
                                            String descricao = (String) request.getParameter("descricao");
                                            pfl = new PerfilDAO().recuperarPerfil(descricao);
                                            if (pfl == null) {
                                                pfl = new Perfil();
                                                pfl.setDescricao((String) request.getParameter("descricao"));
                                                new PerfilDAO().manterPerfil(pfl);
                                                out.println("<script language=\"JavaScript\"> window.location.replace('" + (new String(request.getRequestURL()).split("pages")[0]) + "pages/administracaoPerfilEditar.jsp?perfil="+pfl.getId()+"'); </script>");
                                                out.flush();
                                            } else {
                                                out.println("<strong><center>Perfil já existente na base.</center></strong><br>");
                                            }
                                        } catch (Exception e) {
                                            System.out.println(e.getMessage());
                                            out.println("<strong><center>Falha na Inserção: " + e.getMessage() + ".</center></strong><br>");
                                        }
                                    }
                        %>
                        <table border="1" cellspacing="0" width="300" bgcolor="#FFFFFF">
                            <tr>
                                <td>Descrição do Perfil:</td>
                                <td align="center"><input type="text" name="descricao"></td>
                            </tr>
                            <tr>
                                <td colspan="2" align="center">
                                    <input type="submit" value="Cadastrar">
                                </td>
                            </tr>
                        </table>
                    </form>
                </td>
            </tr>
        </table>
    </body>
</html>